package com.dc.business.datacollectbusiness.service.impl;

import com.dc.business.datacollectbusiness.entity.Line;
import com.dc.business.datacollectbusiness.entity.WorkShop;
import com.dc.business.datacollectbusiness.mapper.LineMapper;
import com.dc.business.datacollectbusiness.mapper.WorkShopMapper;
import com.dc.business.datacollectbusiness.service.LineService;

import com.dc.business.datacollectbusiness.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LineServiceImpl implements LineService {
    @Autowired
    private LineMapper lineMapper;

    @Autowired
    private WorkShopMapper workShopMapper;

    @Override
    public List<Line> getAllLinesByWokShopId(Integer wokShopId) {
        return lineMapper.selectAllLineByWorkShopId(wokShopId);
    }

    @Override
    public void add(Line line) {
        Map<String,Object> map = new HashMap<>();
        map= ThreadLocalUtil.get();
        line.setCreateBy(map.get("username").toString());
        line.setUpdateBy(map.get("username").toString());
        lineMapper.insertLine(line);
    }

    @Override
    public void update(Line line) {
        Map<String,Object> map = new HashMap<>();
        map= ThreadLocalUtil.get();
        line.setUpdateBy(map.get("username").toString());

        WorkShop workShop=new WorkShop();
        workShop.setWorkShopId(line.getWorkShopId());
        workShopMapper.updateWorkShops2(workShop);

        lineMapper.updateLine(line);
    }

    @Override
    public void delete(Integer LineId){
        lineMapper.deleteLineByLineId(LineId);
    }
}
